package com.example.fitapp.activity.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.app.Person;
import android.media.Image;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.fitapp.activity.R;
import com.example.fitapp.activity.adapter.HomeDetailAdapter;
import com.example.fitapp.activity.bean.MySerializable;

public class HomeDetail extends AppCompatActivity {
    private MySerializable mySerializable;
    private ImageView user_image;
    private TextView user_name;
    private TextView rich_text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_detail);

        mySerializable = (MySerializable) getIntent().getSerializableExtra("DetailItem");


        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.detail_recycle);
        user_image = (ImageView) findViewById(R.id.user_image);
        Glide.with(getApplicationContext()).load(mySerializable.getUser_header()).into(user_image);
        user_name = (TextView)findViewById(R.id.user_name);
        if (mySerializable.getName() != ""){
            user_name.setText(mySerializable.getName());
        }else {
            user_name.setText("匿名");
        }

        rich_text = (TextView) findViewById(R.id.rich_text);
        rich_text.setText(mySerializable.getRichText());


        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);

        recyclerView.setLayoutManager(layoutManager);
        HomeDetailAdapter adapter = new HomeDetailAdapter(mySerializable.getImageList());
        recyclerView.setAdapter(adapter);

        TextView rich_text = (TextView) findViewById(R.id.rich_text);

        rich_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Boolean flag = true;
                if (flag){
                    flag =false;
                    rich_text.setEllipsize(null);
                    rich_text.setSingleLine(false);
                }else {
                    flag = true;
                    rich_text.setEllipsize(TextUtils.TruncateAt.END);
                }
            }
        });

    }
}
